package com.theaf.basemodule.web.controller;

import com.theaf.basemodule.common.api.PositionService;
import com.theaf.basemodule.common.condition.PosCondition;
import com.theaf.basemodule.common.dto.PositionDTO;
import com.theaf.basemodule.common.vo.PositionVO;
import com.theaf.core.web.ResultHandler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value="/position")
@Api(value = "/position",description = "岗位请求")
public class PositionController {
    @Autowired
    private PositionService positionService;

    @RequestMapping(value = "/list",  method = RequestMethod.POST)
    @ApiOperation(value = "岗位查询", notes = "岗位查询", response = PositionDTO.class)
    public Object list(@RequestBody @ApiParam(name="查询条件",value="传入json格式",required=true) PosCondition condition){
        return ResultHandler.success(positionService.findCustom(condition));
    }

    @RequestMapping(value = "/get/{id}",  method = RequestMethod.GET)
    @ApiOperation(value = "获取岗位", notes = "获取岗位", response = PositionDTO.class)
    @ApiImplicitParam(value = "用户标识" , name = "id" , dataType = "long" , paramType = "path",required=true)
    public Object get(@PathVariable("id") Long id){
        return ResultHandler.success(positionService.findById(id));
    }

    @RequestMapping(value = "/save",  method = RequestMethod.POST)
    @ApiOperation(value = "获取岗位", notes = "获取岗位", response = Boolean.class)
    public Object save(@RequestBody @ApiParam(name="岗位提交数据",value="传入json格式",required=true) PositionVO positionVO){
        positionService.save(positionVO);
        return ResultHandler.success(true);
    }

    @RequestMapping(value = "/delete/{id}",  method = RequestMethod.DELETE)
    @ApiOperation(value = "删除岗位", notes = "删除岗位", response = Boolean.class)
    @ApiImplicitParam(value = "岗位标识" , name = "id" , dataType = "long" , paramType = "path",required=true)
    public Object delete(@PathVariable("id") Long id){
        positionService.delete(id);
        return ResultHandler.success(true);
    }
}
